package com.taobaolite.history;

import com.taobaolite.user.User;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

@Embeddable
public class HistoryPK implements Serializable {

    @ManyToOne
    @JoinColumn(name = "userId")
    private User user;
    @Column(length = 36,updatable = false,nullable = false)
    private Timestamp time;

    public HistoryPK(User user, Timestamp time) {
        this.user = user;
        this.time = time;
    }

    public HistoryPK() {}

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof HistoryPK)) return false;
        HistoryPK historyPK = (HistoryPK) o;
        return user.equals(historyPK.user) && time.equals(historyPK.time);
    }

    @Override
    public int hashCode() {
        return Objects.hash(user, time);
    }
}
